package test.db.table.mysql.type;

import test.db.table.Table;
import test.db.util.DBUtil;

/**
 * @author newbie
 * @since 0.1
 */
public enum PwTableRowCountTable implements Table {
	TABLE_NAME(Column.tableName),
	ROW_ID(Column.rowId),
	CATEGORY(Column.category),
	TOTAL_CNT(Column.totalCnt),
	NOTICE_CNT(Column.noticeCnt),
	SECRET_CNT(Column.secretCnt),
	EXCLUDE_CNT(Column.excludeCnt),
	DELETE_CNT(Column.deleteCnt);
    
    private final Column column;
    private static final String TYPE_TABLE_NAME = "VARCHAR(20)";
    private static final String TYPE_ROW_ID = "VARCHAR(20)";
    private static final String TYPE_CATEGORY = "BIGINT(18)";
    private static final String TYPE_TOTAL_CNT = "INT(10)";
    private static final String TYPE_NOTICE_CNT = "INT(10)";
    private static final String TYPE_SECRET_CNT = "INT(10)";
    private static final String TYPE_EXCLUDE_CNT = "INT(10)";
    private static final String TYPE_DELETE_CNT = "INT(10)";

    PwTableRowCountTable(Column column) {
        this.column = column;
    }
    
    private enum Column {
        tableName {
            String getType() {
                return TYPE_TABLE_NAME;
            }
        },
        
        rowId {
            String getType() {
                return TYPE_ROW_ID;
            }
        },
        
        category {
            String getType() {
                return TYPE_CATEGORY;
            }
        },
        
        totalCnt {
            String getType() {
                return TYPE_TOTAL_CNT;
            }
        },
        
        noticeCnt {
        	String getType() {
        		return TYPE_NOTICE_CNT;
        	}
        },
        
        secretCnt {
        	String getType() {
        		return TYPE_SECRET_CNT;
        	}
        },
        
        excludeCnt {
            String getType() {
                return TYPE_EXCLUDE_CNT;
            }
        },
        
        deleteCnt {
            String getType() {
                return TYPE_DELETE_CNT;
            }
        };
        
        abstract String getType();
    }
    
    public String getType() {
        return column.getType();
    }
    
    public void initData() throws Exception {
        DBUtil.addData("DELETE FROM PW_TABLE_ROW_COUNT WHERE ROW_TYPE = 'TEST'");
        DBUtil.addData("INSERT INTO PW_TABLE_ROW_COUNT (SELECT 'PW_BBS', 'TEST', CATEGORY_SID, COUNT(*), (SELECT COUNT(*) FROM PW_BBS WHERE BBS_ID = 'TEST' AND CATEGORY_SID = 0 AND SECRET_YN = '1') CNT, 0, 0, 0 FROM PW_BBS WHERE BBS_ID = 'TEST' AND CATEGORY_SID = 0)");
        DBUtil.addData("INSERT INTO PW_TABLE_ROW_COUNT (SELECT 'PW_BBS', 'TEST', CATEGORY_SID, COUNT(*), (SELECT COUNT(*) FROM PW_BBS WHERE BBS_ID = 'TEST' AND CATEGORY_SID = 1 AND SECRET_YN = '1') CNT, 0, 0, 0 FROM PW_BBS WHERE BBS_ID = 'TEST' AND CATEGORY_SID = 1)");
        DBUtil.addData("INSERT INTO PW_TABLE_ROW_COUNT (SELECT 'PW_BBS', 'TEST', CATEGORY_SID, COUNT(*), (SELECT COUNT(*) FROM PW_BBS WHERE BBS_ID = 'TEST' AND CATEGORY_SID = 2 AND SECRET_YN = '1') CNT, 0, 0, 0 FROM PW_BBS WHERE BBS_ID = 'TEST' AND CATEGORY_SID = 2)");
    }
}